package screens
{
	import entities.Player;
	
	import org.flixel.FlxButton;
	import org.flixel.FlxG;
	import org.flixel.FlxGroup;
	import org.flixel.FlxSprite;
	import org.flixel.FlxText;
	import org.flixel.plugin.photonstorm.*;
	
	import tools.MyFlxSprite;
	
	
	public class HudScreen extends FlxGroup
	{
		
		private var score:FlxText;
		private var weapon:FlxText;
		private var position:FlxText;
		private var health:FlxText;
		
		public var healthbar:FlxBar;

		public function HudScreen()  {
			var infos:Object = Registry.gameInfos.hud;
			
			// health bar
			healthbar = new FlxBar(
				infos.healthbarPos ? infos.healthbarPos[0] : 380, infos.healthbarPos ? infos.healthbarPos[1] : 10, 
				FlxBar.FILL_LEFT_TO_RIGHT,
				infos.healthbarSize ? infos.healthbarSize[0] : 100, infos.healthbarSize ? infos.healthbarSize[1] : 18, 
				Registry.player, "health",0,Registry.player.infos.gamePlay.health);
			
			healthbar.scrollFactor.x = healthbar.scrollFactor.y = 0;
			healthbar.color = (infos.healthbarColor) ? infos.healthbarColor : 0xff3333DD;
			add(healthbar);
			
			
			// header image
			if(infos.image){
				var shape:MyFlxSprite = new MyFlxSprite();
				shape.loadGraphicWithBitmap(infos.image);
				shape.x = infos.hudPos[0];
				shape.y = infos.hudPos[1];
				shape.height = infos.hudHeight;
				shape.width = FlxG.width;
				shape.scrollFactor.x =  shape.scrollFactor.y = 0;
				add(shape);
			}
			
			//score
			if(!infos.scorePos) infos.scorePos = new Array(0,0);
			score = new FlxText(infos.scorePos[0] !='' ? infos.scorePos[0] : 260, infos.scorePos[1] !='' ? infos.scorePos[1] : 10, 200, '');
			score.color = 0xffffffff;
			score.shadow = 0xff000000;
			score.size = 14;
			score.scrollFactor.x = score.scrollFactor.y = 0;
			add(score);
			
			health = new FlxText(healthbar.x + healthbar.width/2 - 50, healthbar.y+2, 100);
			health.color = 0xffffffff;
			health.size = 12;
			health.shadow = 0xff000000;
			health.scrollFactor.x =  health.scrollFactor.y = 0;
			add(health);
		}
		
	

		override public function update():void{
			super.update();
			if(Registry.player){
				health.text = Registry.player.health + ' / ' + Registry.player.infos.gamePlay.health;
				score.text= 'SCORE : ' + Registry.player.score ;
				score.text += (Registry.player.infos.gamePlay.lives) ? ' / LIFE : ' + Registry.player.infos.gamePlay.lives + '\nLEVEL  : ' + Registry.player.level : '';
			}
		}
	}

}